import { request } from '../../utils/request'
import { getLiveId } from '../../utils/storage'

const app = getApp();
//验证司仪
export function validateEmcee() {
    return request('emceeUser/validate', 'POST', {});
}

//获取活动信息
export function getLiveInfo() {
    return request('wxScan/saiYaRen', 'POST', {
        splid: getLiveId(),
    });
}

//充值(测试方法)
export function recharge(money) {
    return new Promise((resolve, reject) => {
        request('hmWxmoney/chongzhiMiao', 'post', {
            total: money,
            userId: wx.getStorageSync('userId'),
            openid: wx.getStorageSync('openId')
        }).then(res1 => {
            return pay(res1)
        }).then(res2 => {
            resolve(res2)
        }).catch(err => {
            console.log(err);
            reject(err);
        })
    });
}

//支付(测试方法)
export function pay(param) {
    return new Promise((resolve, reject) => {
        wx.requestPayment({
            'timeStamp': param.obj.timeStamp,
            'nonceStr': param.obj.nonceStr,
            'package': param.obj.package,
            'signType': 'MD5',
            'paySign': param.obj.paySign,
            'success': function (res) {
                console.log(res);
                resolve(res)
            },
            'fail': function (res) {
                reject(res)
            }
        })
    });
}

// 获取签到状态
export function getSignInState() {
    return request('hmScanReportController/getQianDaoInfo', 'GET', {
        splid: getLiveId(),
    });
}
// 签到
export function signIn() {
    return request('hmScanReportController/qianDao', 'POST', {
        splid: getLiveId(),
        wx_name: app.globalData.userInfo.nickName,
        avator: app.globalData.userInfo.avatarUrl,
    });
}

// 订阅消息
export function addSubscribeSize() {
    return request('subscribeController/addSubscribeSize', 'POST', {});
}

// 获取聊天记录
export function getMsgInfo() {
  return request('wxScan/getMsgInfo', 'GET', {
    splid: getLiveId(),
    num: 1,
    size: 30,
  });
}

// 发送聊天消息
export function sendChatMessage(message) {
  return request('sendMsgController/msgGo6', 'POST', {
    splid: getLiveId(),
    content: message,
    color: 0,
  });
}